package com.hezhiqin.xiancheng;

import java.time.LocalTime;

/**
 * @program: homeWork
 * @description:
 * @author: hezhiqin
 * @create: 2019-12-04 21:52
 */
public class SynchronizedDemo {
    public static void main(String[] args) throws InterruptedException {

        Thread t2 = new MyThread2();
        t2.start();
        Thread.sleep(1); // 暂停1毫秒
        t2.interrupt(); // 中断t线程

        Thread t = new MyThread();
        t.setDaemon(true);
        t.start();

    }
}

class MyThread extends Thread {
    @Override
    public void run() {
        while (true) {
            System.out.println(LocalTime.now());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                break;
            }
        }
    }

}


class MyThread2 extends Thread {
    public void run() {
        int n = 0;
        while (! isInterrupted()) {
            n ++;
            System.out.println(n + " hello!");
        }
    }
}
